package com.happycat.configuration;

import com.happycat.config.HappyCatSecurity;
import com.happycat.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvc implements WebMvcConfigurer {

	@Bean
	public JwtInterceptor jwtInterceptor() {
		return new JwtInterceptor();
	}

    @Autowired
    private HappyCatSecurity happyCatSecurity;

	 //自定义过滤规则
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		 //registry.addInterceptor().addPathPatterns("/**").excludePathPatterns(happyCatSecurity.getAntMatchers());
		 InterceptorRegistration registration = registry.addInterceptor(jwtInterceptor());
		 registration.addPathPatterns("/**");
		 //忽略 token 认证的接口
		 registration.excludePathPatterns(happyCatSecurity.getAntMatchers());
	}

}
